﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using Com.CMS263.DAO;

namespace Com.CMS263.BLL
{
    public class ExtValueBLL
    {
        ExtValueDAO eaDAO = new ExtValueDAO();
        /// <summary>
        /// 根据基本文章
        /// </summary>
        /// <param name="artId"></param>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public IList<string> GetShowInBackValue(int artId, int attrId)
        {
            ExtAttributeBLL eaBLL = new ExtAttributeBLL();
            IList<ExtAttribute> attrList = eaBLL.GetShowInBackAttrByTypeId(attrId);
            IList<String> valList = new List<string>();
            //循环扩展属性表根据属性编号和和文章编号得到某个属性的值
            foreach (ExtAttribute item in attrList)
            {
                string val = "";
                if (item.attrType == 4)
                {
                    val = "<img src='/ArtUpFile/" + this.GetValueById(artId, item.id) + "'/>";
                }
                else
                {
                    val = this.GetValueById(artId, item.id);
                }
                valList.Add(val);
            }
            return valList;
        }
        /// <summary>
        /// 根据文章编号和属性编号得到这个属性的值
        /// </summary>
        /// <param name="artId">基本文章编号</param>
        /// <param name="attrId">属性编号</param>
        /// <returns></returns>
        public string GetValueById(int artId, int attrId)
        {
            string val = "";
            try
            {
                val = eaDAO.GetValueById(artId, attrId);
                if (val == null)
                {
                    val = string.Empty;
                }
                return val;
            }
            catch (Exception)
            {
                val = "";
                return val;
            }

        }
        /// <summary>
        /// 根据编号和属性查询这个对象
        /// </summary>
        /// <param name="artId"></param>
        /// <param name="attrId"></param>
        /// <returns></returns>
        public ExtValue GetExtValueById(int artId, int attrId)
        {
            return eaDAO.GetExtValueById(artId, attrId);
        }

        public void Add(ExtValue ext)
        {
            eaDAO.Add(ext);
        }
        /// <summary>
        /// 根据文章编号去除扩展属性值的料条
        /// </summary>
        /// <param name="artId"></param>
        /// <returns></returns>
        internal IList<ExtValue> GetExtValueByArtId(int artId)
        {
            return eaDAO.GetExtValueByBaseArtId(artId);
        }

        #region 根据AttrId查询信息条数
        /// <summary>
        /// 根据AttrId查询信息条数
        /// </summary>
        /// <param name="attrid"></param>
        /// <returns></returns>
        public int GetCounByAttrId(int attrid)
        {
            return eaDAO.GetCounByAttrId(attrid);
        }
        #endregion
    }
}
